package com.example.redisrabbitesintegeation.common.exception;


import com.example.redisrabbitesintegeation.common.config.ResultVO;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @ClassName GlobalExceptionAdvice
 * @Description 全局捕捉异常切面类
 * @Author Kx
 * @Date 2025/9/29 11:37
 * @Version 1.0
 */
@RestControllerAdvice(basePackages = "org.example.web.controller")
public class GlobalExceptionAdvice {

    /**
     * @author: kx
     * @date: 2025/9/29 11:54
     * @param exception : 异常对象
     * @return org.example.common.config.ResultVO<T>
     * @description: 处理自定义的顶层异常
    */
    @ExceptionHandler({GlobalException.class})
    public <T> ResultVO<T> handleGlobalException(GlobalException exception) {
        ResultVO<T> resultVO = new ResultVO<>();
        resultVO.setCode(exception.getCode());
        resultVO.setMessage(exception.getMessage());
        return resultVO;
    }

    /**
     * @author: kx
     * @date: 2025/9/29 11:55
     * @param exception : 异常对象
     * @return org.example.common.config.ResultVO<T>
     * @description: 处理最大的异常
    */
    public <T> ResultVO<T> handleGlobalException(Exception exception) {
        ResultVO<T> resultVO = new ResultVO();
        resultVO.setCode(HttpStatus.INSUFFICIENT_STORAGE.value());
        resultVO.setMessage("服务器繁忙,请稍后尝试");
        return resultVO;
    }
}
